define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'withdraw/index',
                    approve_url: 'withdraw/approve',
                    reject_url: 'withdraw/reject',
                    complete_url: 'withdraw/complete'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true},
                        {field: 'id', title: 'ID'},
                        {field: 'user.nickname', title: __('用户昵称')},
                        {field: 'money', title: __('提现金额'), operate:'BETWEEN'},
                        {field: 'type_text', title: __('提现方式')},
                        {field: 'account', title: __('收款账号')},
                        {field: 'real_name', title: __('真实姓名')},
                        {field: 'status_text', title: __('状态')},
                        {field: 'reason', title: __('驳回原因')},
                        {field: 'createtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: __('更新时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {
                            field: 'operate',
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'approve',
                                    text: __('通过'),
                                    title: __('审核通过'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: 'fa fa-check',
                                    url: $.fn.bootstrapTable.defaults.extend.approve_url,
                                    confirm: '确认通过该提现申请?',
                                    visible: function(row) {
                                        return row.status === 'created';
                                    },
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'reject',
                                    text: __('驳回'),
                                    title: __('驳回申请'),
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    icon: 'fa fa-times',
                                    url: $.fn.bootstrapTable.defaults.extend.reject_url,
                                    visible: function(row) {
                                        return row.status === 'created';
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                search: true,
                showExport: true
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        reject: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});